﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PersonDefinition
{
    class Person
    {
        public string Name { get; set; }
        public int? Age { get; set; }

        public Person(string name, int? age)
        {
            this.Name = name;
            this.Age = age;
        }

        public override string ToString()
        {
            if (this.Age.HasValue)
            {

                return string.Format("Name: {0}, Age: {1}", Name, "No age filled");
            }
            else
            {
                return string.Format("Name: {0}, Age: {1}", Name, Age);
            }
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = 17;
                result = result * 23 + ((Name != null) ? this.Name.GetHashCode() : 0);
                result = result * 23 + ((Age != null) ? this.Age.GetHashCode() : 0);
                return result;
            }
        }

        public bool Equals(Person value)
        {
            return Equals(this.Name, value.Name) &&
                   this.Age.Equals(value.Age);
        }

        public override bool Equals(object obj)
        {
            Person temp = obj as Person;
            if (temp == null) return false;
            return this.Equals(temp);
        }
    }
}
